﻿using ATM.BUS;
using ATM.DAO;
using ATM.Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ATMSystem
{
    public partial class frmAmountTransfer : Form
    {
        private Account passAcc;
        private Card passCard;
        public frmAmountTransfer()
        {
            InitializeComponent();
        }

        public frmAmountTransfer(Account acc,Card card)
        {
            InitializeComponent();
            passAcc = acc;
            passCard = card;
        }

        public string AccCusID;
        public string accReceiveID;
        bool flag;
        private void frmAmountTransfer_Load(object sender, EventArgs e)
        {
            //int amount = int.Parse(txtMoney.Text.Trim());

        }

        //int amount = int.Parse(txtMoney.Text.Trim());
        private void txtReceiveID_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (!char.IsDigit(e.KeyChar) && e.KeyChar != '\b')
            {
                e.Handled = true;
            }
        }


        private void btnClear_Click(object sender, EventArgs e)
        {
            txtAmount.Clear();
            flag = true;
        }

        private void btn_Enter_Click(object sender, EventArgs e)
        {
            try
            {
                double ReceiveBalance = CardTransferBUS.Get_Balance(accReceiveID);
                double customBalance = CardTransferBUS.Get_Balance(AccCusID);
                double amountTranfer = double.Parse(txtAmount.Text.Trim());
                if (customBalance < amountTranfer)
                {
                    flag = false;
                    txtAmount.Text = "Không đủ tiền chuyển!";
                }
                else
                {
                    bool transfer = CardTransferBUS.Transfer(AccCusID, accReceiveID, amountTranfer);
                    if (transfer == true)
                    {
                        frmAskForReceipt frm1 = new frmAskForReceipt();
                        LogDAO.WriteLog(passCard, 2, 1, (float)amountTranfer, "Say Something");
                        frm1.Show();
                    }
                }
            }
            catch
            {
                return;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_Clear_Click(object sender, EventArgs e)
        {
            txtAmount.Text = "";
        }
    }
}
